package com.example.javabasic.thread.classtwo.workthread.demo1;

import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

//生产者 工厂
public class TransportThread extends Thread {
    private final Channel channel;
    private static final Random random = new Random(System.currentTimeMillis());
    private static final AtomicInteger inte = new AtomicInteger(0);

    public TransportThread(String name,Channel channel){
        super(name);
        this.channel = channel;
    }

    @Override
    public void run() {
        for (int i = 0; true ; i++) {

            int i1 = inte.addAndGet(1);
            Request request = new Request("货物"+i1,i1);
            this.channel.put(request);
            try {
                Thread.sleep(random.nextInt(2000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
